import { useClocked } from "@/stores/clocked";
import { copyTextToClipboard } from "@/comm/copy";
import { Notify } from "@/components/y-notify/script";
import { useUser } from "@/stores/user";
import { computed, ref } from "vue";
import { nameList } from "./nameList";
import i18n from "@/locals";
enum MoreType {
    PEOPLE,
    TOALENERGY
}

type EnergyCount = {
    totalInvites: number;
    totalEnergy: number;
    todayEnergy: number;
    totalLuckEnergy: number;
    todayLuckEnergy: number;
}


const user = useUser();
const clocked = useClocked();
const link = computed(() => {
    if (user.info && user.info.recommendCode) {
        return location.origin + "/recommend/" + user.info.recommendCode;
    }
    return "";
});


const onCopy = (txt: string) => {
    copyTextToClipboard(txt);
    Notify.alert(i18n.global.t('message.Global.copy'));
};

function Clocked() {
    clocked.changePopClocked(true);
}

let energyCount = ref<EnergyCount>({
    totalInvites: 0,
    totalEnergy: 0,
    todayEnergy: 0,
    totalLuckEnergy: 0,
    todayLuckEnergy: 0
});

async function getData() {
    const data = await user.getuserEnergyCount<EnergyCount>();
    if (data !== undefined) {
        energyCount.value.totalInvites = data.totalInvites;
        energyCount.value.totalEnergy = data.totalEnergy * 0.01;
        energyCount.value.todayEnergy = data.todayEnergy * 0.01;
        energyCount.value.totalLuckEnergy = data.totalLuckEnergy * 0.01;
        energyCount.value.todayLuckEnergy = data.todayLuckEnergy * 0.01;
    }
    return energyCount.value;
}

function onMoreDown(type: MoreType) {
    switch (type) {
        case MoreType.PEOPLE:
            nameList.open();
            break;
        case MoreType.TOALENERGY:

            break;
    }
}

export { onCopy, Clocked, onMoreDown, getData, energyCount, link, user, MoreType };